<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <eHeader
        :dict="dict"
        :permission="permission"
        :is-archived-options="isArchivedOptions"
        :picker-options="pickerOptions"
        :invoice-status-options="invoiceStatusOptions"
      />
      <crudOperation :permission="permission" />
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      :header-cell-style="headerStyle"
      :cell-style="cellStyle"
      style="width: 100%;"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" fixed label="序号" width="80" />
      <el-table-column prop="contractCode" fixed label="合同编号" width="120" />
      <el-table-column prop="isArchived" label="合同是否存档" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.isArchived ? '是' : '否' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="projectName" label="项目名称" width="300" />
      <el-table-column prop="projectEntrustedCompany" label="委托单位" width="240" />
      <el-table-column prop="projectArea" label="项目区域" width="120" />
      <el-table-column prop="projectAddress" label="项目地点" width="150" />
      <el-table-column prop="projectTypeValue" label="项目类型" width="100" />
      <el-table-column prop="projectSourceValue" label="项目来源" width="100" />
      <el-table-column prop="departmentName" label="承接部门" width="120" />
      <el-table-column prop="projectLeader" label="项目负责人" width="120" />
      <el-table-column prop="projectMainMember" label="项目主要成员" width="150" />
      <el-table-column prop="projectAssistMember" label="项目辅助成员" width="150" />
      <el-table-column prop="projectStartTime" label="开始时间" width="160" />
      <el-table-column prop="projectFinishTime" label="结束时间" width="160" />
      <el-table-column label="项目完成情况">
        <el-table-column prop="projectDesc" label="完成的工作量描述" width="300" />
        <el-table-column prop="projectFinishedRatio" label="完成合同的百分比" width="150" />
      </el-table-column>
      <el-table-column prop="unitPrice" label="单价" width="120" />
      <el-table-column prop="contractAmount" label="合同金额" width="120" />
      <el-table-column prop="finalAmount" label="决算金额" width="120" />
      <el-table-column prop="invoiceAmount" label="开票金额" width="120" />
      <el-table-column prop="invoiceTimestamp" label="开票时间" width="120" />
      <el-table-column prop="invoiceStatus" label="是否已开票" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.invoiceStatus === 1 ? '已开票' : '未开票' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="receivedAmount" label="到账金额" width="120" />
      <el-table-column prop="receivedTimestamp" label="到账时间" width="120" />
      <el-table-column prop="remainBalance" label="剩余尾款" width="120" />
      <el-table-column label="劳务、外业成本">
        <el-table-column prop="collaborator" label="协作人" width="180" />
        <el-table-column prop="collaborationTypeName" label="类型" width="120" />
        <el-table-column prop="collaborationAmount" label="金额" width="120" />
      </el-table-column>
      <el-table-column label="业务">
        <el-table-column prop="businessOperator" label="业务员" width="150" />
        <el-table-column prop="businessAmountRatio" label="业务费比例" width="120" />
        <el-table-column prop="businessDesc" label="说明" width="150" />
      </el-table-column>
      <el-table-column prop="remark" label="备注" width="300" />
      <!--   编辑与删除   -->
      <el-table-column
        v-if="checkPer(['admin','project:edit','project:del'])"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <udOperation
            :data="scope.row"
            :permission="permission"
          />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
    <!--表单渲染-->
    <eForm :dict="dict" :is-archived-options="isArchivedOptions" :invoice-status-options="invoiceStatusOptions" />
  </div>
</template>

<script>
import crudProject from '@/api/project/project'
import eHeader from './module/header'
import eForm from './module/form'
import CRUD, { presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import udOperation from '@crud/UD.operation'
export default {
  name: 'Project',
  components: { eHeader, eForm, crudOperation, pagination, udOperation },
  cruds() {
    return CRUD({
      title: '项目',
      url: 'api/project/getList',
      crudMethod: { ...crudProject }
    })
  },
  mixins: [presenter()],
  // 数据字典
  dicts: ['projectType', 'projectSource', 'undertakeDepartment', 'collaborationType', 'projectAddressId'],
  data() {
    return {
      permission: {
        add: ['admin', 'project:add'],
        edit: ['admin', 'project:edit'],
        del: ['admin', 'project:del']
      },
      isArchivedOptions: [
        { key: 'true', display_name: '是' },
        { key: 'false', display_name: '否' }
      ],
      invoiceStatusOptions: [
        { key: 1, display_name: '已开票' },
        { key: 0, display_name: '未开票' }
      ],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date(new Date().toLocaleDateString())
            const start = new Date(new Date().toLocaleDateString())
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            end.setTime(end.getTime() + 24 * 60 * 60 * 1000 - 1)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date(new Date().toLocaleDateString())
            const start = new Date(new Date().toLocaleDateString())
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            end.setTime(end.getTime() + 24 * 60 * 60 * 1000 - 1)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date(new Date().toLocaleDateString())
            const start = new Date(new Date().toLocaleDateString())
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 92)
            end.setTime(end.getTime() + 24 * 60 * 60 * 1000 - 1)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      headerStyle: {
        textAlign: 'center',
        backgroundColor: '#FFF',
        borderTop: '1px solid #dfe6ec'
      },
      cellStyle: {
        textAlign: 'center'
      }
    }
  },
  methods: {
    // 改变状态
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
 ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
